﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WeChatParking.Core.Payment.WeixinPay
{
    /// <summary>
    /// 类名：WxpayConfig
    /// 功能：基础配置类
    /// 详细：设置帐户有关信息及返回路径
    /// 如何获取安全校验码和合作身份者ID
    /// </summary>
    public class WxpayConfig
    {

        #region 字段

        private static string charset = ""; 
         
        private static string query_order_url = "";

        private static string native_link = "";  

        #endregion

        static WxpayConfig()
        {
            charset = "UTF-8";
             
            query_order_url = "https://api.mch.weixin.qq.com/pay/orderquery";

            native_link = "weixin://wxpay/bizpayurl?appid={0}&mch_id={1}&nonce_str={2}&product_id={3}&time_stamp={4}&sign={5}"; 
        }

        /// <summary>
        /// 微信公众号身份的唯一标识
        /// </summary>
        public static string AppID
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxAppID); }
        }

        /// <summary>
        /// 微信公众号密钥
        /// </summary>
        public static string AppSecret
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxAppSecret); }
        }


        /// <summary>
        /// 商户 ID，身份标识，在微信収送的邮件中查看
        /// </summary>
        public static string MchID
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxPayMchID); }

        }


        /// <summary>
        ///  商户支付密钥 Key
        /// </summary>
        public static string WxPayKey
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxPayKey); }

        }

        /// <summary>
        /// 字符集编码
        /// </summary>
        public static string Charset
        {
            get { return charset; }

        }
        
        /// <summary>
        ///  统一下单接口 API 地址
        /// </summary>
        public static string UnifiedOrderUrl
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxUnifiedOrderUrl); }
        }

         /// <summary>
        ///  查询订单接口 API 地址
        /// </summary>
        public static string QueryOrderUrl
        {
            get { return query_order_url; }
        }

        /// <summary>
        ///  Native支付 静态二维码链接地址
        /// </summary>
        public static string NativeLink
        {
            get { return native_link; }
        }
        //jsapi_ticket_link

        /// <summary>
        /// 获取jsapi_ticket的链接地址
        /// </summary>
        public static string JsApiTicketLink
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxJSApiTicketUrl); }
        }

        /// <summary>
        /// 微信接口访问权限
        /// </summary>
        public static string AccessTokenLink
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxAccessTokenUrl); }
        }

        /// <summary>
        /// 为了获取用户的openid,需先获得Code
        /// </summary>
        public static string GetCodeLink
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxGetCodeUrlFormat); }
        }

        /// <summary>
        /// 获取用户openid的链接，需先获取code
        /// </summary>
        public static string GetOpenIDLink
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxGetOpenIDUrlFormat); }
        }

        /// <summary>
        /// 是否是通联支付渠道
        /// </summary>
        public static bool IsTonglianChannel
        {
            get {
                return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxPayChannel)
                  .Equals("Tonglian", StringComparison.CurrentCultureIgnoreCase);
            }
        }
      

        /// <summary>
        /// 通联支付AppID
        /// </summary>
        public static string TonglianAppId
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.TonglianAppId); }
        }
        /// <summary>
        /// 微信支付通知地址
        /// </summary>
        public static string WxPayNotifyUrl
        {
            get { return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.WxPayNotifyUrl); }
        }

        /// <summary>
        /// 是否使用智慧通行平台渠道
        /// </summary>
        public static bool IsUnionPay
        {
            get
            {
                return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.IsUnionPay)
                  .Equals("true", StringComparison.CurrentCultureIgnoreCase);
            }
        }
        /// <summary>
        /// 应用商户代码，由智慧通行平台分配
        /// </summary>
        public static string UnionPayAppId
        {
            get
            {
                return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.UnionPayAppId);
            }
        }
        /// <summary>
        /// 发起扣款请求的商户号
        /// </summary>
        public static string UnionPayIndustryCode
        {
            get
            {
                return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.UnionPayIndustryCode);
            }
        }
        /// <summary>
        /// 是否使用智慧通行平台渠道
        /// </summary>
        public static string UnionPayKey
        {
            get
            {
                return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.UnionPayKey);
            }
        }
        /// <summary>
        ///  无感出行平台URL
        /// </summary>
        public static string UnionPayUrl
        {
            get
            {
                return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.UnionPayUrl);
            }
        }
        /// <summary>
        ///   支付完成后，智慧通行平台向此url推送支付结果
        /// </summary>
        public static string UnionPayCallback
        {
            get
            {
                return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.UnionPayCallback);
            }
        }
        /// <summary>
        ///  退款完成后，运营商接收退款结果通知的url
        /// </summary>
        public static string UnionPayRefundCallback
        {
            get
            {
                return Core.BLL.SystemConfig.GetConfigValue(Entity.Enums.SystemConfig.UnionPayRefundCallback);
            }
        }
    }

}
